package CarManagement;

import CollegeInformation.Service2;

import javax.swing.*;
import java.awt.event.*;

public class addBigCar extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JButton buttonCancel;
    private JTextField textField1;
    private JTextField textField2;
    private JTextField textField3;
    private JTextField textField4;
    private JTextField textField5;
    private JTextField textField6;
    private JTextField textField7;

    public addBigCar(){}
    public addBigCar(String id) {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);

        buttonOK.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                String license = textField1.getText();
                String company = textField2.getText();
                String  buyTime= textField3.getText();
               int mile = Integer.parseInt(textField4.getText());
                float oilConsumption =Float.parseFloat(textField5.getText()) ;
                int roadMoney = Integer.parseInt(textField6.getText());
                int  passengerNum = Integer.parseInt(textField7.getText());
                float oilPrice=7; int protectMoney=2000;
                float  sum=protectMoney+oilPrice*oilConsumption;
                Service.addFun1(id, license, company, buyTime,"大客车", mile, oilConsumption, protectMoney, roadMoney, sum, passengerNum);
                dispose();
            }
        });

        buttonCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

        // 单击十字时调用 onCancel()
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // 遇到 ESCAPE 时调用 onCancel()
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    private void onCancel() {
        // 必要时在此处添加您的代码
        dispose();
    }


}
